home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / prtfrm51.zip / FRMSRC.ZIP / FDEMO15.PAS < prev    next >
Pascal/Delphi Source File  |  1996-06-20  |  7KB  |  220 lines

  1. unit Fdemo15;
  2.  
  3. interface
  4.  
  5. uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
  6.   StdCtrls, PrnWin, ExtCtrls, DBTables, DB, Printers, DBCtrls, CB_Types;
  7.  
  8. type
  9.   TForm15 = class(TForm)
  10.     Bevel1: TBevel;
  11.     Memo1: TMemo;
  12.     Table1: TTable;
  13.     Table2: TTable;
  14.     Query1: TQuery;
  15.     Query2: TQuery;
  16.     Query3: TQuery;
  17.     DataSource1: TDataSource;
  18.     DataSource2: TDataSource;
  19.     DataSource3: TDataSource;
  20.     DataSource4: TDataSource;
  21.     DataSource5: TDataSource;
  22.     Query1SpeciesNo: TFloatField;
  23.     Query1Category: TStringField;
  24.     Query1Common_Name: TStringField;
  25.     Table1NAME: TStringField;
  26.     Table1SIZE: TSmallintField;
  27.     Table1WEIGHT: TSmallintField;
  28.     Table1AREA: TStringField;
  29.     Query2Name: TStringField;
  30.     Query2Capital: TStringField;
  31.     Query2Continent: TStringField;
  32.     Query2Population: TFloatField;
  33.     Query3Company: TStringField;
  34.     Query3Phone: TStringField;
  35.     Query3LastInvoiceDate: TDateTimeField;
  36.     Preview: TBitBtn;
  37.     Exit: TBitBtn;
  38.     Table2IND_CODE: TSmallintField;
  39.     Table2IND_NAME: TStringField;
  40.     Table2LONG_NAME: TStringField;
  41.     Table1BMP: TBlobField;
  42.     DBImage1: TDBImage;
  43.     DBImage2: TDBImage;
  44.     Query1Graphic: TGraphicField;
  45.     PrintWin1: TPrintWin;
  46.     procedure PreviewClick(Sender: TObject);
  47.   private
  48.     { Private declarations }
  49.   public
  50.     { Public declarations }
  51.   end;
  52.  
  53. var
  54.   Form15: TForm15;
  55.  
  56. implementation
  57.  
  58. {$R *.DFM}
  59.  
  60. procedure TForm15.PreviewClick(Sender: TObject);
  61. var
  62.     i: Integer;
  63.    Right, Bottom, Top: Real;
  64. begin
  65.    PrintWin1.BeginPrint;
  66.  
  67.    { This will take a bit of programming! }
  68.  
  69.    { Set a nice big font }
  70.    PrintWin1.NewFont ('Arial',20,True,True,True); { The 3 True's are for Bold,
  71.                                                    Italic and Underline }
  72.  
  73.    { And change the color to Red }
  74.    PrintWin1.SetTheTextColor (RGB(255,0,0));
  75.  
  76.    { Draw the text in the Center of the page }
  77.    PrintWin1.DrawText( 1.0,poCenter,'A 4-Page Demo for TPrintWin');
  78.  
  79.    { Draw the first table }
  80.    PrintWin1.NewFont ('Arial',14,False,False,True);
  81.    PrintWin1.SetTheTextColor (RGB(0,0,255));
  82.    PrintWin1.DrawText( 2.0,poLeft,'Here is a list of animals from Table1');
  83.    PrintWin1.DrawTable( 2.3, poLeft, Table1, True, False);
  84.  
  85.    { Draw the 2nd table }
  86.    PrintWin1.SetTheTextColor (RGB(0,0,255));
  87.    PrintWin1.DrawText( 4.6,poLeft,'Here is another Table');
  88.    PrintWin1.DrawTable( 5.0, poLeft, Table2, True, False);
  89.  
  90.    { Draw the 2nd table again}
  91.    PrintWin1.SetTheTextColor (RGB(0,0,0));
  92.    PrintWin1.DrawText( 2.0,poRight,'Repeating Table2');
  93.    PrintWin1.DrawTable( 2.3, poRight, Table2, True, False);
  94.  
  95.    { And the 1st Query }
  96.    PrintWin1.SetTheTextColor (RGB(0,255,0));
  97.    PrintWin1.DrawText( 4.6,poRight,'Here is a Query');
  98.    PrintWin1.DrawQuery( 5.0, poRight, Query1, True, False);
  99.  
  100.    { And Draw some lines in different colors, added some Printer info }
  101.    Bottom := PrintWin1.PageHeight - 1;
  102.    Top := Bottom - 1.5;
  103.    Right := 1.01;
  104.    for i := 0 to 30 do begin
  105.        if i mod 3 = 0 then
  106.            PrintWin1.SelectPen(1, RGB(255,0,0));
  107.        if i mod 3 = 1 then
  108.            PrintWin1.SelectPen(1, RGB(0,255,0));
  109.        if i mod 3 = 2 then
  110.            PrintWin1.SelectPen(1, RGB(0,0,255));
  111.  
  112.       PrintWin1.DrawLine( 0.5, Top, Right, Bottom);
  113.       Top := Top + 0.03;
  114.       Right := Right + 0.07;
  115.       Bottom := Bottom - 0.03;
  116.  
  117.       PrintWin1.DrawLine( 0.5, Bottom, Right, Top);
  118.    end;
  119.  
  120.    { And Frame them nicely }
  121.    Bottom := PrintWin1.PageHeight - 1;
  122.    Top := Bottom - 1.5;
  123.    PrintWin1.SetTheTextColor (RGB(0,0,255));
  124.    PrintWin1.DrawText(Top - 0.3,poLeft,'Draw a few lines');
  125.    PrintWin1.DrawLine(0.5,Top,Right,Top);
  126.    PrintWin1.DrawLine(0.5,Bottom,Right,Bottom);
  127.    PrintWin1.DrawLine(0.5,Top,0.5,Bottom);
  128.    PrintWin1.DrawLine(Right,Top,Right,Bottom);
  129.  
  130.    { Print a Bitmap }
  131.    PrintWin1.DrawText(Top - 0.3,poRight,'Draw an Image');
  132.    PrintWin1.PrintBitmap(PrintWin1.PageWidth -2.5,Top,2,2,DBImage1.Picture.Bitmap);
  133.  
  134.    { Now we switch the header on again }
  135.    PrintWin1.HeaderEnabled := True;
  136.    PrintWin1.HeaderFilled := True;
  137.    PrintWin1.HeaderOutlined := True;
  138.    PrintWin1.HeaderStringCenter := 'Ah, Now we have a header again';
  139.  
  140.    { And go on to the second page }
  141.    PrintWin1.NewPage;
  142.  
  143.    { Draw the text in the Center of the 2nd page }
  144.    PrintWin1.NewFont ('Arial',20,True,True,True);
  145.    PrintWin1.DrawText( 1.6,poCenter,'2nd Page of a 4-Page Demo for TPrintWin');
  146.  
  147.    { Draw the 2nd Query }
  148.    PrintWin1.NewFont ('Arial',14,False,False,True);
  149.    PrintWin1.SetTheTextColor (RGB(0,0,255));
  150.    PrintWin1.DrawText( 2.3,poCenter,'Name some countries in North America');
  151.    PrintWin1.DrawText( 2.6,poCenter,'and keep to the Center');
  152.    PrintWin1.DrawQuery( 3, poCenter, Query2, False, False);
  153.  
  154.    { Draw the 2nd Query }
  155.    PrintWin1.NewFont ('Arial',14,True,False,True);
  156.    PrintWin1.SetTheTextColor (RGB(255,0,0));
  157.    PrintWin1.DrawText( 5.6,poCenter,'And now I have to make some phone calls');
  158.    PrintWin1.DrawText( 6,poCenter,'and keep to the Center');
  159.    PrintWin1.DrawQuery( 6.3, poCenter, Query3, False, False);
  160.  
  161.    { and Maybe just add a single Record from the phone calls query }
  162.    PrintWin1.NewFont ('Arial',14,True,False,True);
  163.    PrintWin1.SetTheTextColor (RGB(0,0,0));
  164.    PrintWin1.DrawText( 8,poLeft,'And now for a single record');
  165.    PrintWin1.NewFont ('Arial',14,False,True,False);
  166.    PrintWin1.DrawQueryRecord( 1, 8.3, Query3);
  167.  
  168.    { And go on to the 3rd page }
  169.    PrintWin1.NewPage;
  170.  
  171.    { Here we need a heading }
  172.    PrintWin1.NewFont ('Arial',20,True,True,True);
  173.    PrintWin1.DrawText( 1.6,poCenter,'3rd Page of a 4-Page Demo for TPrintWin');
  174.  
  175.    { Now we need an image, We might as well use some animals from
  176.      table1
  177.      Note: The DBImage component is used to extract the bitmap and
  178.      TPrintWin Prints it}
  179.  
  180.    { First draw a grid }
  181.    PrintWin1.NewFont ('Arial',14,True,False,False);
  182.    PrintWin1.DrawGrid(0.5,2.3,2.3,2.3,3,3);
  183.    for i := 0 to 2 do begin
  184.      PrintWin1.DrawTextAt( 0.8,2.4+(2.3*i),Table1Name.AsString);
  185.      PrintWin1.PrintBitmap(0.8,2.8+(2.3*i),1.6,1.6,DBImage1.Picture.Bitmap);
  186.      Table1.Next;
  187.  
  188.      { There are only 7 images in the table, so return }
  189.      if i < 2 then begin
  190.         PrintWin1.DrawTextAt( 3.1,2.4+(2.3*i),Table1Name.AsString);
  191.         PrintWin1.PrintBitmap(3.1,2.8+(2.3*i),1.6,1.6,DBImage1.Picture.Bitmap);
  192.         Table1.Next;
  193.         PrintWin1.DrawTextAt( 5.4,2.4+(2.3*i),Table1Name.AsString);
  194.         PrintWin1.PrintBitmap(5.4,2.8+(2.3*i),1.6,1.6,DBImage1.Picture.Bitmap);
  195.         Table1.Next;
  196.      end;
  197.    end;
  198.  
  199.    { And go on to the 4rd page and get the BLOB's from the Query}
  200.    PrintWin1.NewPage;
  201.  
  202.    { Here we need a heading }
  203.    PrintWin1.NewFont ('Arial',14,True,True,True);
  204.    PrintWin1.DrawText( 1.6,poCenter,'4th Page of a 4-Page Demo for TPrintWin');
  205.    for i := 0 to 2 do begin
  206.      PrintWin1.PrintBitmap(1,2.6+(2.3*i),1.6,1.6,DBImage2.Picture.Bitmap);
  207.      Query1.Next;
  208.  
  209.      PrintWin1.PrintBitmap(3.3,2.6+(2.3*i),1.6,1.6,DBImage2.Picture.Bitmap);
  210.      Query1.Next;
  211.      PrintWin1.PrintBitmap(5.6,2.6+(2.3*i),1.6,1.6,DBImage2.Picture.Bitmap);
  212.      Query1.Next;
  213.    end;
  214.  
  215.  
  216.    PrintWin1.EndPrint;
  217. end;
  218.  
  219. end.
  220.